package com.Jano.service.impl;

import com.Jano.exception.BusinessException;
import com.Jano.mapper.UserMapper;
import com.Jano.model.UserModel;
import com.Jano.service.UserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * description: UserServiceImpl <br>
 * date: 2022/7/10 11:04 PM <br>
 * author: zoumaoji <br>
 * version: 1.0 <br>
 */

@Service
public class UserServiceImpl extends AbstractBaseServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    /**
     * 根据用户id查找用户信息
     * @author zoumaoji
     * @date 2022/07/15 17:11
     * @param id
     * @return com.Jano.model.UserModel
     */
    @Override
    public UserModel findById(Integer id) {
        throwIfNull(id, "用户id不能为空");
        return userMapper.selectById(id);

    }

    /**
     * 用户登录
     * @author zoumaoji
     * @date 2022/07/15 17:12
     * @param username
     * @param password
     * @return com.Jano.model.UserModel
     */
    @Override
    public UserModel findByLogin(String username, String password) {
        throwIfBlank(username, "用户名不能为空");
        throwIfBlank(password, "密码不能为空");
        UserModel userModel = userMapper.selectByLogin(username, password);
        throwIfNull(userModel, "用户不存在");
        return userModel;
    }
}
